/**
 * Created by LG on 2017/9/20.
 */
// function refresh(){
//     layer.load(2);
//     document.getElementById("mainFrame").contentWindow.Ajaxpage();
// }


function export2(url) {
    window.location.href = url;
    layer.closeAll();
}

//取消
function layuihide() {
    $(".layui-layer").remove();
    $(".layui-layer-shade").remove();
}
// 返回上一页
function returnBack() {
    history.back();
    // window.history.go(-1)
    // window.parent.location.reload();
    // console.log(document.referrer);
    // window.location.replace(document.referrer);
}
// 订单、工单、产品返回上一页
function returnBackSession() {
    var sessionData = JSON.parse(sessionStorage.getItem('sessionData'));
    var sessionUrl = sessionStorage.getItem('sessionUrl');
    if (isExit(sessionUrl)) {
        console.log('sessionData', parseParams(sessionData));
        console.log('sessionUrl', sessionUrl);
        // return;
        // window.location.replace(document.referrer);
        var urls = sessionUrl + "?" + parseParams(sessionData)+"&fetch_page=1";
        window.location.href = urls;

    } else {
        window.location.replace(document.referrer);
    }
}

var parseParams = function (param) {
    let paramStr = "";
    for (let key in param) {
        paramStr += "&" + key + "=" + param[key];
    }
    return paramStr.substr(1);
}

// 判断值是否存在
function isExit(str) {
    if (str == null || str == '' || str == undefined)
        return false;
    else
        return true;
}
//总后台
/*
 *   合同详情
 */
//备注添加成功
function Addremarksuccess(url, i, contract_id) {
    var remark = $("#remark_" + i + "").val();
    var equipments_id = $("#remark_id_" + i + "").val();
    // console.log(remark)
    $.get(url, {
        remark: remark,
        id: i,
        contract_id: contract_id,
        equipments_id: equipments_id
    }, function (flag) {
        // console.log(flag)
        if (flag.code == 1) {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 1
            });
            $("#mainFrame").attr('src', '/admin/contractinfo/details?contract_id=' + contract_id + '&rand=' + Math.random() + '#equipment');
        } else {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 0
            });
        }
    });
    $(".layui-layer-shade").remove();
    $(".layui-layer").remove();

}

//修改设备成功
function modifyinformationsuccess(url, i, contract_id) {
    // console.log(i)
    var equipments_name = $("#equipments_name_" + i + "").val();
    var equipments_number = $("#equipments_number_" + i + "").val();
    var equipments_id = i;
    var reg = /^[0-9]*[1-9][0-9]*$/;
    if (equipments_name == '') {
        parent.layer.msg("请选择设备型号", {
            time: 1000,
            icon: 0
        })
        return false;
    }
    if (!reg.test(equipments_number)) {
        $("#equipments_number_" + i + "").val('');
        parent.layer.msg("请输入正确的设备编号", {
            time: 1000,
            icon: 0
        })
        return false;
    }
    $.get(url, {
        id: i,
        contract_id: contract_id,
        equipments_number: equipments_number,
        equipments_name: equipments_name,
        equipments_id: equipments_id
    }, function (flag) {
        console.log(flag)
        if (flag.code == 1) {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 1
            });
            $("#mainFrame").attr('src', '/admin/contractinfo/details?contract_id=' + contract_id + '&rand=' + Math.random() + '#equipment');
        } else {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 0
            });
        }
    });
    $(".layui-layer-shade").remove();
    $(".layui-layer").remove();

}
//取消
function layuihides() {
    $(".layui-layer-shade").remove();
    $(".layui-layer").remove();
}

// 导航栏锚点点击

//顶部导航
function locateAt(e) {
    var y = $("#" + e).offset().top;
    while ($("#" + e).html() == $("#" + e).offsetParent().html()) {
        y += $("#" + e).offset().top;
    }
    y -= 60; /*悬浮菜单的高度*/
    $("#overflow", parent.document).scrollTop(y);
}

//---------------------------------------END----------------------------------------------------

//行政区域

//备注添加成功
function Addremarksuccess_Administrative(url, i, contract_id) {

    var remark = $("#remark_" + i + "").val();
    var equipments_id = $("#remark_id_" + i + "").val();
    // console.log(remark)
    $.get(url, {
        id: i,
        contract_id: contract_id,
        remark: remark,
        equipments_id: equipments_id
    }, function (flag) {
        // console.log(flag)
        if (flag.code == 1) {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 1
            });
            $("#mainFrame").attr('src', '/administrative/contractinfo/details?contract_id=' + contract_id + '&rand=' + Math.random() + '#equipment');
        } else {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 0
            });
        }
    });
    $(".layui-layer-shade").remove();
    $(".layui-layer").remove();

}

//修改设备成功
function modifyinformationsuccess_Administrative(url, i, contract_id) {
    // console.log(i)
    var equipments_name = $("#equipments_name_" + i + " option:selected").val();
    var equipments_id = i;
    var equipments_number = $("#equipments_number_" + i + "").val();
    var reg = /^[0-9]*[1-9][0-9]*$/;
    if (equipments_name == '') {
        parent.layer.msg("请选择设备型号", {
            time: 1000,
            icon: 0
        })
        return false;
    }
    if (!reg.test(equipments_number)) {
        $("#equipments_number_" + i + "").val('');
        parent.layer.msg("请输入正确的设备编号", {
            time: 1000,
            icon: 0
        })
        return false;
    }
    $.get(url, {
        id: i,
        contract_id: contract_id,
        equipments_number: equipments_number,
        equipments_name: equipments_name,
        equipments_id: equipments_id
    }, function (flag) {
        console.log(flag)
        if (flag.code == 1) {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 1
            }, function () {
                $(".layui-layer-shade").remove();
                $(".layui-layer").remove();
            });
            $("#mainFrame").attr('src', '/administrative/contractinfo/details?contract_id=' + contract_id + '&rand=' + Math.random() + '#equipment');
        } else {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 0
            }, function () {
                $(".layui-layer-shade").remove();
                $(".layui-layer").remove();
            });
        }
    });
    $(".layui-layer-shade").remove();
    $(".layui-layer").remove();
}

//取消
function cancelmodel() {
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}

//删除合同确定
function delconfirm(obj) {
    layer.msg('删除成功', {
        time: 1000,
        icon: 1
    })
    $(obj).parent().remove();
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}

//弹窗选择
function subback(type) {
    var user_id = $("input[name='user_id']:checked").val();
    var telphone = $("#telphone" + user_id).val();
    if (type == 2) {
        // console.info(telphone);
        $('#mainFrame').contents().find("#customer_introducer_name").val(telphone);
        $('#mainFrame').contents().find("#introducer_id").val(user_id);
    } else {
        var username = $("#cusername" + user_id).val();
        $("#customer_name").val(username);
        $("#user_id").val(user_id);
        $('#mainFrame').contents().find("#customer_name").val(username);
        $('#mainFrame').contents().find("#user_id").val(user_id);
        $('#mainFrame').contents().find("#contact_person").val(username);
        $('#mainFrame').contents().find("#phone").val(telphone);

    }
    cancelmodel();
}
//弹窗搜索
function searchCustomer() {
    document.getElementById("mainFrame").contentWindow.Ajaxpage();
}

function jumpcustome() {
    $("#mainFrame").attr('src', '/administrative/Customerinfo/add' + '#equipment');
    cancelmodel();
}

// 指派工程人员弹窗，新增工程人员按钮
function engineeradd() {
    $("#mainFrame").attr('src', '/administrative/Engineer/add' + '#equipment');
    cancelmodel();
}

// 工程人员排序
// changeArrow
function changeArrow(type, work_order_id) {
    if (type == 1) {
        // 接单率
        changeImg('receiptRate', work_order_id, type);
    } else if (type == 2) {
        // 好评率
        changeImg('praiseRate', work_order_id, type);
    } else if (type == 3) {
        // 已接单数
        changeImg('acceptRate', work_order_id, type);
    } else if (type == 4) {
        // 未完成单数
        changeImg('unfinishRate', work_order_id, type);
    } else if (type == 5) {
        // 退单率
        changeImg('refundRate', work_order_id, type);
    } else if (type == 0) {
        // 退单率
        changeImg('distance', work_order_id, type);
    }
}
// 改变图片
function changeImg(id, work_order_id, type) {
    var src = $("#" + id).attr("src");
    var url1 = src.split("images/")[0] + 'images/';
    var url2 = src.split("images/")[1];
    $(".arrow-sort").val('');
    $(".arrow").attr("src", url1 + "arrow.png");
    //distance_sort,receive_rate_sort,praise_rate_sort,receive_order_sort,uncomplate_order_sort,return_rate_sort
    if (url2 == 'arrow.png') {
        if (type == 1) {
            $("#receive_rate_sort").val(1);
        } else if (type == 2) {
            $("#praise_rate_sort").val(1);
        } else if (type == 3) {
            $("#receive_order_sort").val(1);
        } else if (type == 4) {
            $("#uncomplate_order_sort").val(1);
        } else if (type == 5) {
            $("#return_rate_sort").val(1);
        } else if (type == 0) {
            $("#distance_sort").val(1);
        }
        $("#" + id).attr("src", url1 + "arrow-1.png")
    }
    if (url2 == 'arrow-1.png') { //降序
        if (type == 1) {
            $("#receive_rate_sort").val(2);
        } else if (type == 2) {
            $("#praise_rate_sort").val(2);
        } else if (type == 3) {
            $("#receive_order_sort").val(2);
        } else if (type == 4) {
            $("#uncomplate_order_sort").val(2);
        } else if (type == 5) {
            $("#return_rate_sort").val(2);
        } else if (type == 0) {
            $("#distance_sort").val(2);
        }
        $("#" + id).attr("src", url1 + "arrow-2.png")
    }
    if (url2 == 'arrow-2.png') { //升序
        if (type == 1) {
            $("#receive_rate_sort").val(1);
        } else if (type == 2) {
            $("#praise_rate_sort").val(1);
        } else if (type == 3) {
            $("#receive_order_sort").val(1);
        } else if (type == 4) {
            $("#uncomplate_order_sort").val(1);
        } else if (type == 5) {
            $("#return_rate_sort").val(1);
        } else if (type == 0) {
            $("#distance_sort").val(1);
        }
        // $("#"+id).attr("src",url1+"arrow.png")
        $("#" + id).attr("src", url1 + "arrow-1.png")

    }
    document.getElementById("mainFrame").contentWindow.Ajaxpages(1, work_order_id)

}

// 获取选中的用户
function qwer() {
    var isEmpty = true;
    $("#list input").each(function () {
        if ($(this).is(":checked")) {
            var username = $(this).val();
            var userid = $(this).attr('data');
            var telphone = $(this).attr('telphone');
            var id_card = $(this).attr('id_card');
            var source_name = $(this).attr('source_name');
            var source_tel = $(this).attr('source_tel');
            var province_code = $(this).attr('province_code');
            var city_code = $(this).attr('city_code');
            var area_code = $(this).attr('area_code');
            var user_address = $(this).attr('user_address');
            var whereis = $('#mainFrame').contents().find("#whereis").val();
            //获取老客户
            var is_old_client = $(this).attr('is_old_client');
            var old_client_name = $(this).attr('old_client_name');
            var old_client_tel = $(this).attr('old_client_tel');

            if (is_old_client == 1) {
                $('#mainFrame').contents().find("#old_client_name").html(old_client_name);
                $('#mainFrame').contents().find("#old_client_tel").html(old_client_tel);
                $('#mainFrame').contents().find(".old_client").css('display', 'block');
            } else {
                $('#mainFrame').contents().find(".old_client").css('display', 'none');
            }

            //工单显示默认地址，没有值不操作
            if (whereis != 3 && province_code != 'null' && city_code != 'null' && area_code != 'null' && user_address != 'null') {
                //省
                $('#mainFrame').contents().find("#_province").val(province_code);
                if (whereis == 2) {
                    $('#mainFrame')[0].contentWindow.getSon($('#mainFrame').contents().find("#_province"), 1);
                } else {
                    $('#mainFrame')[0].contentWindow.province_();
                }
                //市
                $('#mainFrame').contents().find("#_city").val(city_code);
                if (whereis == 2) {
                    $('#mainFrame')[0].contentWindow.getSon($('#mainFrame').contents().find("#_city"), 2);
                } else {
                    $('#mainFrame')[0].contentWindow.city_();
                }
                //区
                $('#mainFrame').contents().find("#_area").val(area_code);
                $('#mainFrame').contents().find("#addressDetail").val(user_address);
                $('#mainFrame').contents().find("input[name='user_address']").val(user_address);
                if (whereis == 2) {
                    $('#mainFrame')[0].contentWindow.setVal($('#mainFrame').contents().find("#_area"), 'userarea');
                } else {
                    $('#mainFrame')[0].contentWindow.area_();
                }

                //重新定位
                $('#mainFrame')[0].contentWindow.clickLocation();
            }


            //工单显示用户推荐人信息
            $('#mainFrame').contents().find("#sourceName").html(source_name);
            $('#mainFrame').contents().find("#sourceTel").html(source_tel);

            // 将选中用户id存入隐藏域
            $('#mainFrame').contents().find("#user_id").val(userid);
            // 将选中用户姓名显示在input中
            $('#mainFrame').contents().find("input[name='_username']").val(username);
            // 用户电话
            // $('#mainFrame').contents().find("input[name='telphone']").val(telphone);
            // 用户身份证
            // $('#mainFrame').contents().find("input[name='id_card']").val(id_card);
            // 新增用户推荐人信息userinfo
            var html1 = '<div class="col-sm-12">' +
                    '<div class="col-sm-2 inputText">推荐人电话</div>' +
                    '<div class="col-sm-5">' + telphone + '</div>' +
                    '</div>';
            $('#mainFrame').contents().find("#userInfoTel").html(html1);
            $('#mainFrame').contents().find("#userInfoTel").css("display", "block");
            var html2 = '<div class="col-sm-12">' +
                    '<div class="col-sm-2 inputText">推荐人身份证号码</div>' +
                    '<div class="col-sm-5">' + id_card + '</div>' +
                    '</div>';
            $('#mainFrame').contents().find("#userInfoCard").html(html2);
            $('#mainFrame').contents().find("#userInfoCard").css("display", "block");

            // 新增工单选择用户信息

            var html3 = '<div class="col-sm-3 inputText">用户电话</div>' +
                    '<div class="col-sm-8">' + telphone + '</div>';
            $('#mainFrame').contents().find("#selectInfoTel").html(html3);
            $('#mainFrame').contents().find("#selectInfoTel").css("display", "block");
            var html4 = '<div class="col-sm-3 inputText">身份证号</div>' +
                    '<div class="col-sm-8">' + id_card + '</div>';
            $('#mainFrame').contents().find("#selectInfoCard").html(html4);
            $('#mainFrame').contents().find("#selectInfoCard").css("display", "block");

            // 联系人
            $('#mainFrame').contents().find("input[name='contacts']").val(username);
            // 联系人电话
            $('#mainFrame').contents().find("input[name='contact_number']").val(telphone);
            // 清空设备编号
            $('#mainFrame').contents().find("input[name='device_no']").val('');
            // 清空设备分类id隐藏域
            $('#mainFrame').contents().find("#equipments_id").val('');
            // 清空设备ID 隐藏域
            $('#mainFrame').contents().find("#equipment_id").val('');
            //合同地址
            // $('#mainFrame').contents().find("#_province").val('');
            // $('#mainFrame').contents().find("#_city").val('');
            // $('#mainFrame').contents().find("#_area").val('');
            // $('#mainFrame').contents().find("#addressDetail").val('');
            isEmpty = false;
            return false;
        } else {
            isEmpty = true;
        }
    })
    if (isEmpty) {
        console.log();
        setTimeout(function () {
            layer.msg('请选择用户', {icon: 0});
        }, 100)
    }
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}


// 获取选中的用户
function qwerReport() {
    $("#list input").each(function () {
        if ($(this).is(":checked")) {
            var username = $(this).val();
            var userid = $(this).attr('data');
            console.info(username);
            console.info(userid);
            // 将选中用户id存入隐藏域
            $('#mainFrame').contents().find("#user_id").val(userid);
            // 将选中用户姓名显示在input中
            $('#mainFrame').contents().find("input[name='_username']").val(username);
        }
    })
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}

// 获取选中的设备
function contractqr() {
    $("#clist input").each(function () {
        if ($(this).is(":checked")) {
            var device_no = $(this).val();
            var equipments_id = $(this).attr('equipments_id');
            var equipment_id = $(this).attr('equipment_id');
            // 设备的安装地址
            var province = $(this).attr('province');
            var city = $(this).attr('city');
            var area = $(this).attr('area');
            var address = $(this).attr('address');
            // 经纬度
            var lat = $(this).attr('lat');
            var lng = $(this).attr('lng');

            // 将选中设备分类id存入隐藏域
            $('#mainFrame').contents().find("#equipments_id").val(equipments_id);
            // 将选中设备id存入隐藏域
            $('#mainFrame').contents().find("#equipment_id").val(equipment_id);
            // 将选中的设备编号编号显示在input中
            $('#mainFrame').contents().find("input[name='device_no']").val(device_no);
            // 将安装地址code传到添加页面
            document.getElementById("mainFrame").contentWindow.threeLevel(province, city, area, address, lat, lng);

            // 选择合同后执行获取设备信息
            // document.getElementById("mainFrame").contentWindow.equipmentssss(contract_id);
        }
    })
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}

// 工单管理--获取选中的产品
function getChooseEquipments() {
    $("#clist input").each(function () {
        if ($(this).is(":checked")) {
            var equipments_id = $(this).val();
            var equipments_name = $(this).attr('equipments_name');
            var equipments_type = $(this).attr('equipments_type');
            var equipments_purchase_money = $(this).attr('equipments_purchase_money');
            document.getElementById("mainFrame").contentWindow.getOrderStatus(equipments_type);
            if (equipments_type == 2) {
                console.log('2');
                $('#mainFrame').contents().find("#Setmeal").addClass('hide');
            }
            if (equipments_type == 1) {
                console.log('1');
                $('#mainFrame').contents().find("#Setmeal").removeClass('hide');
                getEquipmentsPackage(equipments_id);
            }
            $('#mainFrame').contents().find("#equipments_name").val(equipments_name);
            $('#mainFrame').contents().find("#equipments_id").val(equipments_id);
            $('#mainFrame').contents().find("#equipments_type").val(equipments_type);
            $('#mainFrame').contents().find("#equipments_purchase_money").val(equipments_purchase_money);
        }
    })
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}
//选择产品后获取产品套餐信息
function getEquipmentsPackage(equipments_id) {
    $.getJSON('/api/Equipments/getPackage', {
        equipments_id: equipments_id
    }, function (data) {
        var html = '';
        for (var i = 0; i < data.length; i++) {
            html += "<option value='" + data[i].package_id + "'>" + data[i].total_money + "元/" + data[i].num + data[i].unit_name + "</option>"
        }
        $('#mainFrame').contents().find("#package").html("");
        $('#mainFrame').contents().find("#package").html(html)

    });
}

// 合同管理--获取选中的产品
function getChooseEquipments2() {
    $("#clist input").each(function () {
        if ($(this).is(":checked")) {
            var equipments_id = $(this).val();
            var equipments_name = $(this).attr('equipments_name');
            $('#mainFrame').contents().find("#equipments_name").val(equipments_name);
            $('#mainFrame').contents().find("#equipments_id").val(equipments_id);

            var equipments_type = $(this).attr('equipments_type');
            var equipments_purchase_money = $(this).attr('equipments_purchase_money');
            $('#mainFrame').contents().find("#equipments_type").val(equipments_type);
            $('#mainFrame').contents().find("#equipments_purchase_money").val(equipments_purchase_money);
            if (equipments_type == 2) {
                $('#mainFrame').contents().find("#Setmeal").addClass('hide');
            }
            if (equipments_type == 1) {
                $('#mainFrame').contents().find("#Setmeal").removeClass('hide');
                getEquipmentsPackage(equipments_id);
            }
        }
    })
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}

// 用户模糊搜索事件
function search() {
    console.log('11');
    // 调用分页
    document.getElementById("mainFrame").contentWindow.Ajaxpage(1);
}
// 客户管理-复制-客户列表搜索
function userSearch() {
    document.getElementById("mainFrame").contentWindow.AjaxpageUser(1);
}
// 设备模糊搜索事件
function search_() {
    // 调用分页
    document.getElementById("mainFrame").contentWindow.Ajaxpages(1);
}
// 工程人员模糊搜索事件
function searcheq(work_order_id) {
    // 调用分页
    document.getElementById("mainFrame").contentWindow.Ajaxpages(1, work_order_id);
}
// 工单指派工程人员确认按钮操作
function engineersqr(work_id) {
    $("#elist input").each(function () {
        if ($(this).is(":checked")) {
            var engineers_id = $(this).val(); // 工程人员id
            var engineers_name = $(this).attr('data'); // 工程人员姓名
            var engineers_number = $(this).attr('number'); // 工程人员编号
            var engineers_phone = $(this).attr('telphone'); // 工程人员电话
            var detail = $(this).attr('detail'); // 详情页面
            // 表示详情页面直接指派
            if (detail == 1) {
                // 调用处理指派任务方法
                document.getElementById("mainFrame").contentWindow.Handles(engineers_id, engineers_number, engineers_name, engineers_phone);
                // 调用AssignResult方法，处理指派结果
                document.getElementById("mainFrame").contentWindow.AssignResults();
                var srcs = "/administrative/workorder/detail?id=" + work_id;
                $("#mainFrame").attr("src", srcs)
            } else {
                // 调用处理指派任务方法
                document.getElementById("mainFrame").contentWindow.Handle(engineers_id, engineers_number, engineers_name, engineers_phone);
                // 调用AssignResult方法，处理指派结果
                document.getElementById("mainFrame").contentWindow.AssignResult();
                // 调用分页
                document.getElementById("mainFrame").contentWindow.Ajaxpage(1);
            }
        }
    });
    $('.layui-layer-shade').remove();
    $('.layui-layer').remove();
}

//解绑设备
//id	解绑设备ID
//url	后端地址
//type	端
function unBind(url, id, contract_id, type) {
    // console.log(contract_id)
    // console.log(type)
    $.get(url, {
        id: id
    }, function (flag) {
        if (flag.code == 1) {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 1
            });
            $("#mainFrame").attr('src', '/' + type + '/contractinfo/details?contract_id=' + contract_id + '&rand=' + Math.random() + '#equipment');
        } else {
            layer.msg(flag.msg, {
                time: 1000,
                icon: 0
            });
        }
        $(".layui-layer-shade").remove();
        $(".layui-layer").remove();
    });
}
//通过工程人员id 查询对应工单数目
function jed(id, name, type, status) {
    var uid = '#a' + id;
    if (type == 1) {
        $(uid, window.parent.document).parent().click();
        $(uid, window.parent.document).click();
        $("#gcry", window.parent.document).val(name);
        $("#gstatus", window.parent.document).val(status);
        $('#mainFrame', window.parent.document).attr("src", '/admin/workorder/index');
    }
    if (type == 2) {
        $(uid, window.parent.document).parent().click();
        $(uid, window.parent.document).click();
        $("#gcry", window.parent.document).val(name);
        $("#gstatus", window.parent.document).val(status);
        $('#mainFrame', window.parent.document).attr("src", '/administrative/workorder/index');
    }
    if (type == 3) {
        $(uid, window.parent.document).parent().click();
        $(uid, window.parent.document).click();
        $("#gcry", window.parent.document).val(name);
        $("#gstatus", window.parent.document).val(status);
        $('#mainFrame', window.parent.document).attr("src", '/operation/workorder/index');
    }
}

//优惠使用
function recommend(id, cid) {
    var log = $('#log').val();
    var tem = 1;
    if (log == null || log == undefined || log == '') {
        top.layer.msg('请填写备注！', {
            icon: 2
        });
        tem = 0;
    }
    if (id == null || id == '' || id == undefined) {
        top.layer.msg('请选择推荐设备后操作！', {
            icon: 2
        });
        tem = 0;
    }
    if (tem == 1) {
        $.getJSON('/administrative/customerinfo/recommend', {
            id: id,
            log: log
        }, function (data) {
            top.layer.msg(data.message, {
                icon: data.status,
                time: 300
            }, function () {
                $('#mainFrame', window.parent.document).attr("src", '/administrative/customerinfo/devicedetails/cid/' + cid);
                $('.layui-layer-shade').remove();
                $('.layui-layer').remove();
            });
        });
    }
}

//Firefox兼容
function Browser() {
    var explorer = navigator.userAgent;
    if (explorer.indexOf("Firefox") >= 0) {
        $('#overflow', window.parent.document).css('overflow-y', 'hidden');
    }
}
Browser()

//限制翻页
function inputlength() {
    var pagenum = $("#allpage i").html();
    $('.laypage_total input').attr('max', pagenum);
    var text = document.getElementsByClassName('laypage_skip')[0];
    if (text) {
        text.onkeyup = function () {
            this.value = this.value.replace(/\D/g, '');
            if (text.value > pagenum) {
                text.value = pagenum;
            }
        }
    }
}

//验证积分
function checkMoney(obj) {
    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
}
//关闭提示
function removenotice() {
    $(".noticeText").hide();
}

// function checkMoney(obj){
// 	console.log('checkMoney');
//     var money = obj.value;
//     var name = obj.name;
//     var tip = /^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/;
//     var reg = new RegExp(tip);
//     if(!reg.test(money)){
//         top.layer.msg('积分输入格式不对，请重新输入', {
//             icon: 0,
//             time: 1000
//         });
//         $(obj).val('');
//     }
// }

//关闭弹窗
function cancel() {
    layer.closeAll();
}
// 确定
function ensure() {
    var doorsills = $("#doorsills").val();
    document.getElementById("mainFrame").contentWindow.confirmEnsure(doorsills);
}
//获取验证码
function getscode() {
    console.log('获取验证码');
}
// 修改手机
function jumpchangephone(tel_name, tel) {
    $("#mainFrame").attr('src', '/admin/account/changePhone?tel_name=' + tel_name + '&tel=' + tel + '#equipment');
    cancelmodel();
}

/**
 * 自定义套餐，获取套餐信息
 * @param id	产品ID
 */
function packageInfo(url) {
    var id = $('#mainFrame').contents().find("#equipmentsName").val();
    var package_mode = $("#package_mode").val();
    $.getJSON(url, {
        id: id
    }, function (data) {
        $.each(data.data, function (k, v) {
            //若有相同模式？？？？
            if (v.mode == package_mode) {
                pac_service_new_money = ((v.new_service_money / v.total_money) * 100).toFixed(2);
                pac_service_renew_money = ((v.renew_service_money / v.renew_money) * 100).toFixed(2);
                $("#package_num").val(v.num);
                $("#package_total_money").val(v.total_money);
                $("#package_renew_money").val(v.renew_money);
                $("#package_cycle").val(v.cycle);
                $("#package_service_new_money").val(pac_service_new_money);
                $("#package_service_renew_money").val(pac_service_renew_money);
                return true;
            }
        });
    });
}

//客户管理-交换手机号
function exchangeTel(exchange_userid, user_id) {
    $.getJSON('/admin/customerinfo/exchangeTel', {
        exchange_userid: exchange_userid,
        user_id: user_id
    }, function (data) {
        top.layer.msg(data.msg, {
            icon: data.code,
            time: 2000
        }, function () {
            if (data.code == 1) {
                document.getElementById("mainFrame").contentWindow.Ajaxpage(1);
                $('.layui-layer-shade').remove();
                $('.layui-layer').remove();
            }

        });
    });
}
//客户管理-交换实名认证
function exchangeAuth(exchange_userid, user_id) {
    $.getJSON('/admin/customerinfo/exchangeAuth', {
        exchange_userid: exchange_userid,
        user_id: user_id
    }, function (data) {
        top.layer.msg(data.msg, {
            icon: data.code,
            time: 2000
        }, function () {
            if (data.code == 1) {
                document.getElementById("mainFrame").contentWindow.Ajaxpage(1);
                $('.layui-layer-shade').remove();
                $('.layui-layer').remove();
            }

        });
    });
}
//获取页面URL地址
function GetUrlRelativePath(url) {
    if (url == '' || !url) {
        var url = document.location.toString();
    } else {
        url = location.origin + url;
    }

    var arrUrl = url.split("//");
    var start = arrUrl[1].indexOf("/");
    var relUrl = arrUrl[1].substring(start);//stop省略，截取从start开始到结尾的所有字符
    if (relUrl.indexOf("?") != -1) {
        relUrl = relUrl.split("?")[0];
    }
    return relUrl;
}
